package com.example.mqdemo.rabbitmq.publishquee.directexchange.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PublishConfig {

    //初始化队列
    @Bean
    Queue queuePublish(){
        return new Queue("publish");
    }

    //初始化交换机

    /**
     * 队列名
     * 重启之后是否有效
     * 是否自动删除
     * @return
     */
    @Bean
    DirectExchange directExchange(){
        return new DirectExchange("direct",true,false);
    }

    //队列与交换机绑定
    @Bean
    Binding binding(){
        return BindingBuilder.bind(queuePublish()).to(directExchange()).with("direct");
    }
}
